<template>
  <div>
    <!--引用表格-->
   <BasicTable @register="registerTable" :rowSelection="rowSelection">
     <!--插槽:table标题-->
      <template #tableTitle>
          <!--
          <a-button  type="primary" preIcon="ant-design:plus-outlined" @click="batchGeneratePayHandle">生成缴费单</a-button>
          -->
          <a-button  type="primary" preIcon="ant-design:plus-outlined" @click="batchRefundHandle">批量退款</a-button>
      </template>

      <template #statusSlot="{ record }">
        <Tag v-if="record.status=='0'" color="yellow">否</Tag>
        <Tag v-if="record.status=='1'" color="green">是</Tag>
      </template>
    </BasicTable>

  </div>
</template>

<script lang="ts" name="cssubjectorder-csSubjectOrder" setup>
  import {reactive} from 'vue';
  import { Tag } from 'ant-design-vue';
  import {BasicTable} from '/@/components/Table';
  import { useListPage } from '/@/hooks/system/useListPage'
  import {payPersonColumns, searchPayPersonSchema} from './CsSubjectOrder.data';
  import {orderStatistics, batchRefund,batchGeneratePay} from './CsSubjectOrder.api';
  import { useMessage } from '/@/hooks/web/useMessage';
  const { createMessage } = useMessage();
  const queryParam = reactive<any>({});

  //注册table数据
  const { tableContext } = useListPage({
      tableProps:{
           title: '线下科目缴费统计',
           api: orderStatistics,
           columns:payPersonColumns,
           canResize:false,
           showActionColumn:false,
           clickToRowSelect:true,
          //  rowKey:'personId',
           formConfig: {
              // autoAdvancedCol:4,
              //labelWidth: 120,
              schemas: searchPayPersonSchema,
              autoSubmitOnEnter:true,
              showAdvancedButton:true,
              fieldMapToNumber: [
              ],
              fieldMapToTime: [
                 ['createTime', ['createTime_begin', 'createTime_end'], 'YYYY-MM-DD'],
              ],
            },
           actionColumn: {
               width: 120,
               fixed:'right'
            },
            beforeFetch: (params) => {
              return Object.assign(params, queryParam);
            },
      }
  })

  const [registerTable, {reload},{ rowSelection, selectedRowKeys,selectedRows }] = tableContext
  

   /**
    * 批量生成缴费单事件
    */
   function batchGeneratePayHandle() {
     if(selectedRowKeys.value.length==0){
       createMessage.error('请先勾选数据')
     }else{
      let selectedData = new Array();
      selectedRows.value.forEach(item=>{
        selectedData.push({
          personId:item.id,
          semesterId:item.semesterId
        })
      });

      console.log(selectedData);
      batchGeneratePay({rows: selectedData});
    }
  }

    /**
    * 批量生成缴费单事件
    */
   function batchRefundHandle() {
     if(selectedRowKeys.value.length==0){
       createMessage.error('请先勾选数据')
     }else{
      let selectedData = new Array();
      selectedRows.value.forEach(item=>{
        selectedData.push({
          personId:item.id,
          semesterId:item.semesterId
        })
      });

      batchRefund({rows: selectedData});
    }
     
   }
  

</script>

<style scoped>

</style>